﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Xml.Linq;

namespace TurtleEngine.Databases
{
	 /// <summary>
	 ///
	 /// </summary>
	 public class BaseConnect : ICommunicate, IConnect
	 {
		  /// <summary>
		  /// Allows us to access the assembly to get the queries
		  /// </summary>
		  protected Assembly Assembly;

		  /// <summary>
		  /// Stores the custom queries to get/store the details from the database
		  /// </summary>
		  protected List<DbQuery> Queries;

		  /// <summary>
		  /// Adds the column details.
		  /// </summary>
		  /// <param name="columnInfo">The column info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddColumnDetails(DataRow columnInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the function details.
		  /// </summary>
		  /// <param name="functionInfo">The function info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddFunctionDetails(DataRow functionInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the procedure details.
		  /// </summary>
		  /// <param name="procedureInfo">The procedure info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddProcedureDetails(DataRow procedureInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the table details.
		  /// </summary>
		  /// <param name="tableInfo">The table info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddTableDetails(DataRow tableInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the trigger details.
		  /// </summary>
		  /// <param name="triggerInfo">The trigger info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddTriggerDetails(DataRow triggerInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the uddt details.
		  /// </summary>
		  /// <param name="uddtInfo">The uddt info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddUddtDetails(DataRow uddtInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Adds the view details.
		  /// </summary>
		  /// <param name="viewInfo">The view info.</param>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void AddViewDetails(DataRow viewInfo)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Checks the server online.
		  /// </summary>
		  /// <param name="server">The server.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual bool CheckServerOnline(string server)
		  {
				// Ping the server so we're not hanging around waiting for a response that will never come
				var ping = new Ping();
				var reply = ping.Send(server, 3 * 1000); // 3 seconds time out (in ms)
				if (reply == null) return false;
				if (reply.Status == IPStatus.Success)
					 return true;

				return false;
		  }

		  /// <summary>
		  /// Connects the specified connection string.
		  /// </summary>
		  /// <param name="connectionString">The connection string.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual bool Connect(string connectionString)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Connections the string builder.
		  /// </summary>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual string ConnectionStringBuilder()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Disconnects this instance.
		  /// </summary>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual void Disconnect()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Finds the database instances.
		  /// </summary>
		  /// <param name="server">The server.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual bool FindDatabaseInstances(string server)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Finds the database servers.
		  /// </summary>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataTable FindDatabaseServers()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the column details.
		  /// </summary>
		  /// <param name="table">The table.</param>
		  /// <param name="column">The column.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetColumnDetails(string table, string column)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the database instances.
		  /// </summary>
		  /// <param name="server">The server.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataTable GetDatabaseInstances(string server)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the functions in the database
		  /// </summary>
		  /// <returns>Datatable of functions in database</returns>
		  public virtual DataTable GetFunctions()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the index details.
		  /// </summary>
		  /// <param name="index">The procedure.</param>
		  /// <returns></returns>
		  public virtual DataRow GetIndexDetails(string index)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets all Indexes in database
		  /// </summary>
		  /// <returns>Table with a list of all the Indexes</returns>
		  public virtual DataTable GetIndexes()
		  {
				throw new NotImplementedException();
		  }

		  public virtual DataTable GetInfoFromDatabase(DbQuery sourceQuery, string val1, string val2)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the procedure details.
		  /// </summary>
		  /// <param name="procedure">The procedure.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetProcedureDetails(string procedure)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the stored procedures in the database
		  /// </summary>
		  /// <returns>Datatable of the stored procedures in database</returns>
		  public virtual DataTable GetProcedures()
		  {
				throw new NotImplementedException();
		  }

		  public void GetQueries(XDocument doc)
		  {
				var queryList = from d in doc.Root.Descendants("Queries")
									 select d;

				Queries = new List<DbQuery>();

				foreach (var q in queryList)
				{
					 DbQuery temp = new DbQuery();
					 temp.Name = q.Attribute("Name").Value;
					 temp.Unique1 = q.Attribute("Unique1").Value;
					 temp.Unique2 = q.Attribute("Unique2").Value;
					 temp.ConditionType = q.Attribute("ConditionType").Value;
					 temp.QueryString = q.Value;
				}
		  }

		  /// <summary>
		  /// Gets the table column details.
		  /// </summary>
		  /// <param name="table">The table.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataTable GetTableColumnDetails(string table)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the table details.
		  /// </summary>
		  /// <param name="table">The table.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetTableDetails(string table)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the tables in the database
		  /// </summary>
		  /// <returns>Datatable of tables in database</returns>
		  public virtual DataTable GetTables()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the trigger details.
		  /// </summary>
		  /// <param name="view">The view.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetTriggerDetails(string view)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the triggers in the database
		  /// </summary>
		  /// <returns>Datatable of triggers in database</returns>
		  public virtual DataTable GetTriggers()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the uddt details.
		  /// </summary>
		  /// <param name="view">The view.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetUddtDetails(string view)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the user-defined data types in the database
		  /// </summary>
		  /// <returns>Datatable of user-defined data types in database</returns>
		  public virtual DataTable GetUddts()
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets the view details.
		  /// </summary>
		  /// <param name="view">The view.</param>
		  /// <returns></returns>
		  /// <exception cref="System.NotImplementedException"></exception>
		  public virtual DataRow GetViewDetails(string view)
		  {
				throw new NotImplementedException();
		  }

		  /// <summary>
		  /// Gets a list of all the views in the database
		  /// </summary>
		  /// <returns>Datatable of views in database</returns>
		  public virtual DataTable GetViews()
		  {
				throw new NotImplementedException();
		  }
	 }
}